package com.newenergy.wisehome.common.util;

import android.os.Build;
import android.os.LocaleList;

import java.util.Locale;

/**
 * 获取系统语言
 * Created by KYX on 2018/1/11.
 */

public class LocaleUtil {

    /**
     *
     * @return 返回系统语言
     */
    public static String getLanguage (){
        Locale locale;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            locale = LocaleList.getDefault().get(0);
        } else {
            locale = Locale.getDefault();
        }
        String language = locale.getLanguage().toLowerCase() ;

        return language;
    }


    /**
     *
     * @return 返回系统地区语言
     */
    public static String getCountryLanguage (){
        Locale locale;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            locale = LocaleList.getDefault().get(0);
        } else {
            locale = Locale.getDefault();
        }
        String language = locale.getLanguage() + "-" + locale.getCountry();

        return language;
    }
}
